package com.qyhl.shop.shop.rush;

import com.qyhl.shop.common.ShopUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.shop.ShopRushListBean;

import java.util.List;

public class ShopRushPurchaseModel implements ShopRushPurchaseContract.ShopRushPurchaseModel {
    private ShopRushPurchasePresenter mPresenter;

    public ShopRushPurchaseModel(ShopRushPurchasePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getListByShop(int shopId, int page) {
        EasyHttp.post(ShopUrl.SHOP_RUSH_PURCHASE_SHOP_LIST)
                .params("shopId", shopId + "")
                .params("page", page + "")
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("phoneNum", CommonUtils.getInstance().getUserName())
                .execute(new SimpleCallBack<List<ShopRushListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取抢购列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopRushListBean> bean) {
                        mPresenter.setList(bean);
                    }
                });
    }

    @Override
    public void getListBySite(int page) {
        EasyHttp.post(ShopUrl.SHOP_RUSH_PURCHASE_SITE_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("page", page + "")
                .params("phoneNum", CommonUtils.getInstance().getUserName())
                .execute(new SimpleCallBack<List<ShopRushListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取抢购列表失败！");
                    }

                    @Override
                    public void onSuccess(List<ShopRushListBean> bean) {
                        mPresenter.setList(bean);
                    }
                });
    }
}
